import { createStore, useStore as useVueStore } from 'vuex'
import type { TRootState, TStoreType } from './type'
import type { Store } from 'vuex'
import login from './login/login'
import mv from './mv-video/mv-video'
import music from './play-music/play-music'

const store = createStore<TRootState>({
  state: {
    name: 'kzj'
  },
  mutations: {},
  actions: {},
  modules: {
    login,
    mv,
    music
  }
})

//初始化本地数据与vuex数据联系
//防止刷新后vuex数据脱失 需要在main.ts中使用
export function setupStore() {
  store.dispatch('login/loadLocalLogin')
}

//重写userStore增加模块类型
export function useStore(): Store<TStoreType> {
  return useVueStore()
}

export default store
